package com.siwei.mes.entity.experiment.slag;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 矿渣粉-烧矢量
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class SlagSsl {
    @ApiModelProperty(value = "矿渣灼烧测得的三氧化硫质量分数")
    private String zssyhl;
    @ApiModelProperty(value = "矿渣未经灼烧测得的三氧化硫质量分数")
    private String wzssyhl;
    @ApiModelProperty(value = "矿渣灼烧过程中吸收空气中氧的质量分数")
    private String zskqy;
    @ApiModelProperty(value = "烧失量平均值")
    private String sslpjz;
    @ApiModelProperty(value = "烧失量矫正值")
    private String ssljzz;
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "烧矢量信息")
    private List<SlagSsl.SslInfo> sslInfo = Collections.singletonList(new SlagSsl.SslInfo());

    @Data
    @Accessors(chain = true)
    @ApiModel("烧矢量信息")
    public class SslInfo {
        @ApiModelProperty(value = "称量器皿质量")
        private String clqmzl;
        @ApiModelProperty(value = "试料+称量器皿质量")
        private String slclqmzl;
        @ApiModelProperty(value = "试料质量")
        private String slzl;
        @ApiModelProperty(value = "瓷坩埚质量")
        private String cggzl;
        @ApiModelProperty(value = "灼烧后试料+瓷坩埚质量")
        private String zshcggzl;
        @ApiModelProperty(value = "灼烧后试样质量")
        private String zshsyzl;
        @ApiModelProperty(value = "烧失量结果")
        private String ssl;
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        SlagSsl entity = new SlagSsl();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, SlagSsl.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, SlagSsl.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        SlagSsl entity = JsonUtils.getObject(objJson, SlagSsl.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getSslpjz()) || "null".equals(entity.getSslpjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }

    public static void setValue(SlagSsl entity, Map<String, Object> data) {
        if(data.get("shaoShiLiangPingJun") != null){
            entity.setSslpjz(data.get("shaoShiLiangPingJun").toString());
        }
        if(data.get("shaoShiLiangJiaoZhen") != null){
            entity.setSsljzz(data.get("shaoShiLiangJiaoZhen").toString());
        }
        List<SlagSsl.SslInfo> sslInfo = entity.getSslInfo();
        if(data.get("qmZl1") != null){
            sslInfo.get(0).setClqmzl(data.get("qmZl1").toString());
        }
        if(data.get("yQmZl1") != null){
            sslInfo.get(0).setSlclqmzl(data.get("yQmZl1").toString());
        }
        if(data.get("slZl1") != null){
            sslInfo.get(0).setSlzl(data.get("slZl1").toString());
        }
        if(data.get("cqgZl1") != null){
            sslInfo.get(0).setCggzl(data.get("cqgZl1").toString());
        }
        if(data.get("zhuoShaoHouSYCqgZl1") != null){
            sslInfo.get(0).setZshcggzl(data.get("zhuoShaoHouSYCqgZl1").toString());
        }
        if(data.get("zhuoShaoHouSyZl1") != null){
            sslInfo.get(0).setZshsyzl(data.get("zhuoShaoHouSyZl1").toString());
        }
        if(data.get("shaoShiLiang1") != null){
            sslInfo.get(0).setSsl(data.get("shaoShiLiang1").toString());
        }
    }
}
